// BCFuglMeyerBalPage.cpp : implementation file
//

#include "stdafx.h"
#include "../Frame/GYWalkAidApp.h"
#include "BCFuglMeyerBalPage.h"
#include "../Common/LinkComboBox.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CBCFuglMeyerBalPage dialog

static INPUT_FIELD_INFO s_InputFieldArray1[] = 
{
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("10"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("20"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("30"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("40"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("50"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("60"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("70"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("80"),		ftString,	FALSE,	0,	2,		NULL,		NULL	},
};

static INPUT_FIELD_INFO s_InputFieldArray2[] = 
{
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("10"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("20"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("30"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("40"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("50"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("60"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("70"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("80"),		ftString,	FALSE,	0,	2,		NULL,		NULL	},
};

static INPUT_FIELD_INFO s_InputFieldArray3[] = 
{
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("10"),		ftString,	FALSE,	0,	1,		CBCFuglMeyerBalPage::ScoreFieldsCheck,		CBCFuglMeyerBalPage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("20"),		ftString,	FALSE,	0,	1,		CBCFuglMeyerBalPage::ScoreFieldsCheck,		CBCFuglMeyerBalPage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("30"),		ftString,	FALSE,	0,	1,		CBCFuglMeyerBalPage::ScoreFieldsCheck,		CBCFuglMeyerBalPage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("40"),		ftString,	FALSE,	0,	1,		CBCFuglMeyerBalPage::ScoreFieldsCheck,		CBCFuglMeyerBalPage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("50"),		ftString,	FALSE,	0,	1,		CBCFuglMeyerBalPage::ScoreFieldsCheck,		CBCFuglMeyerBalPage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("60"),		ftString,	FALSE,	0,	1,		CBCFuglMeyerBalPage::ScoreFieldsCheck,		CBCFuglMeyerBalPage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("70"),		ftString,	FALSE,	0,	1,		CBCFuglMeyerBalPage::ScoreFieldsCheck,		CBCFuglMeyerBalPage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("80"),		ftString,	FALSE,	0,	2,		NULL,										NULL	},
};


CBCFuglMeyerBalPage::CBCFuglMeyerBalPage(CWnd* pParent, BOOL bBigRes) : CScrollPage(bBigRes ? CBCFuglMeyerBalPage::IDD : CBCFuglMeyerBalPage::SD_IDD, pParent)
, m_edtFMLB101(&m_InputFieldArray1[0]),	m_edtFMLB201(&m_InputFieldArray2[0]),	m_edtFMLB301(&m_InputFieldArray3[0])
, m_edtFMLB102(&m_InputFieldArray1[1]),	m_edtFMLB202(&m_InputFieldArray2[1]),	m_edtFMLB302(&m_InputFieldArray3[1])
, m_edtFMLB103(&m_InputFieldArray1[2]),	m_edtFMLB203(&m_InputFieldArray2[2]),	m_edtFMLB303(&m_InputFieldArray3[2])
, m_edtFMLB104(&m_InputFieldArray1[3]),	m_edtFMLB204(&m_InputFieldArray2[3]),	m_edtFMLB304(&m_InputFieldArray3[3])
, m_edtFMLB105(&m_InputFieldArray1[4]),	m_edtFMLB205(&m_InputFieldArray2[4]),	m_edtFMLB305(&m_InputFieldArray3[4])
, m_edtFMLB106(&m_InputFieldArray1[5]),	m_edtFMLB206(&m_InputFieldArray2[5]),	m_edtFMLB306(&m_InputFieldArray3[5])
, m_edtFMLB107(&m_InputFieldArray1[6]),	m_edtFMLB207(&m_InputFieldArray2[6]),	m_edtFMLB307(&m_InputFieldArray3[6])
, m_edtFMLB108(&m_InputFieldArray1[7]),	m_edtFMLB208(&m_InputFieldArray2[7]),	m_edtFMLB308(&m_InputFieldArray3[7])
{
	//{{AFX_DATA_INIT(CBCFuglMeyerBalPage)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	
	LPVOID pCtrl = NULL;
	DWORD dwControlType = IBT_NoneType;
	for(int i = 0; i < INPUT_EDIT_CTRL_COUNT; i++)
	{
		pCtrl = m_InputFieldArray1[i].pLinkCtrl;
		dwControlType = m_InputFieldArray1[i].dwCtrlType;
		memcpy(&m_InputFieldArray1[i], &s_InputFieldArray1[i], sizeof(INPUT_FIELD_INFO));
		m_InputFieldArray1[i].pLinkCtrl = pCtrl;
		m_InputFieldArray1[i].dwCtrlType = dwControlType;
		
		pCtrl = m_InputFieldArray2[i].pLinkCtrl;
		dwControlType = m_InputFieldArray2[i].dwCtrlType;
		memcpy(&m_InputFieldArray2[i], &s_InputFieldArray2[i], sizeof(INPUT_FIELD_INFO));
		m_InputFieldArray2[i].pLinkCtrl = pCtrl;
		m_InputFieldArray2[i].dwCtrlType = dwControlType;
		
		pCtrl = m_InputFieldArray3[i].pLinkCtrl;
		dwControlType = m_InputFieldArray3[i].dwCtrlType;
		memcpy(&m_InputFieldArray3[i], &s_InputFieldArray3[i], sizeof(INPUT_FIELD_INFO));
		m_InputFieldArray3[i].pLinkCtrl = pCtrl;
		m_InputFieldArray3[i].dwCtrlType = dwControlType;
	}
}


void CBCFuglMeyerBalPage::DoDataExchange(CDataExchange* pDX)
{
	CScrollPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBCFuglMeyerBalPage)
	DDX_Control(pDX, IDC_EDIT_SCORE46, m_edtFMLB101);
	DDX_Control(pDX, IDC_EDIT_SCORE55, m_edtFMLB102);
	DDX_Control(pDX, IDC_EDIT_SCORE59, m_edtFMLB103);
	DDX_Control(pDX, IDC_EDIT_SCORE157,m_edtFMLB104);
	DDX_Control(pDX, IDC_EDIT_SCORE162,m_edtFMLB105);
	DDX_Control(pDX, IDC_EDIT_SCORE169,m_edtFMLB106);
	DDX_Control(pDX, IDC_EDIT_SCORE174,m_edtFMLB107);
	DDX_Control(pDX, IDC_EDIT_SCORE176,m_edtFMLB108);

	DDX_Control(pDX, IDC_EDIT_SCORE47, m_edtFMLB201);
	DDX_Control(pDX, IDC_EDIT_SCORE56, m_edtFMLB202);
	DDX_Control(pDX, IDC_EDIT_SCORE60, m_edtFMLB203);
	DDX_Control(pDX, IDC_EDIT_SCORE158,m_edtFMLB204);
	DDX_Control(pDX, IDC_EDIT_SCORE163,m_edtFMLB205);
	DDX_Control(pDX, IDC_EDIT_SCORE170,m_edtFMLB206);
	DDX_Control(pDX, IDC_EDIT_SCORE175,m_edtFMLB207);
	DDX_Control(pDX, IDC_EDIT_SCORE177,m_edtFMLB208);

	DDX_Control(pDX, IDC_EDIT_SCORE48, m_edtFMLB301);
	DDX_Control(pDX, IDC_EDIT_SCORE57, m_edtFMLB302);
	DDX_Control(pDX, IDC_EDIT_SCORE58, m_edtFMLB303);
	DDX_Control(pDX, IDC_EDIT_SCORE152,m_edtFMLB304);
	DDX_Control(pDX, IDC_EDIT_SCORE160,m_edtFMLB305);
	DDX_Control(pDX, IDC_EDIT_SCORE166,m_edtFMLB306);
	DDX_Control(pDX, IDC_EDIT_SCORE172,m_edtFMLB307);
	DDX_Control(pDX, IDC_EDIT_SCORE173,m_edtFMLB308);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBCFuglMeyerBalPage, CScrollPage)
	//{{AFX_MSG_MAP(CBCFuglMeyerBalPage)
	ON_WM_VSCROLL()
	ON_WM_SIZE()
	ON_WM_MOUSEWHEEL()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBCFuglMeyerBalPage message handlers

void CBCFuglMeyerBalPage::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	//...
	
	CScrollPage::OnVScroll(nSBCode, nPos, pScrollBar);
}

void CBCFuglMeyerBalPage::OnSize(UINT nType, int cx, int cy) 
{
	CScrollPage::OnSize(nType, cx, cy);
	
	//...
}

BOOL CBCFuglMeyerBalPage::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) 
{
	//...
	
	return CScrollPage::OnMouseWheel(nFlags, zDelta, pt);
}

BOOL CBCFuglMeyerBalPage::ClearData()
{
	INPUT_FIELD_INFO* ppCtrlArray[3];
	ppCtrlArray[0] = m_InputFieldArray1;
	ppCtrlArray[1] = m_InputFieldArray2;
	ppCtrlArray[2] = m_InputFieldArray3;
	
	CWnd* apDateLabel[3];
	apDateLabel[0] = GetDlgItem(IDC_STATIC_FMLB_DATE_1);
	apDateLabel[1] = GetDlgItem(IDC_STATIC_FMLB_DATE_2);
	apDateLabel[2] = GetDlgItem(IDC_STATIC_FMLB_DATE_3);
	
	CWnd* apDiagSNArray[3];
	apDiagSNArray[0] = GetDlgItem(IDC_STATIC_DIAGSN1);
	apDiagSNArray[1] = GetDlgItem(IDC_STATIC_DIAGSN2);
	apDiagSNArray[2] = GetDlgItem(IDC_STATIC_DIAGSN3);
	
	return PageClearData(ppCtrlArray, INPUT_EDIT_CTRL_COUNT, apDateLabel, apDiagSNArray, ARRAY_ELE_COUNT(apDateLabel));
}

int CBCFuglMeyerBalPage::SaveData(CString strMRN, int nDiagSN, BOOL bIsDraft)
{
	INPUT_FIELD_INFO* ppCtrlArray[3];
	ppCtrlArray[0] = m_InputFieldArray1;
	ppCtrlArray[1] = m_InputFieldArray2;
	ppCtrlArray[2] = m_InputFieldArray3;

	return PageSaveData(strMRN, nDiagSN, bIsDraft, BODYCHECKSCALEID, ppCtrlArray, INPUT_EDIT_CTRL_COUNT);
}

BOOL CBCFuglMeyerBalPage::ScoreFieldsCheck(LPVOID pParam)
{
	CBCFuglMeyerBalPage* pParent = NULL;
	INPUT_FIELD_INFO* pFieldInfo = (INPUT_FIELD_INFO*)pParam;
	
	if(pFieldInfo->dwCtrlType == IBT_EditBox)
	{
		CLinkEdit* pEdit = (CLinkEdit*)pFieldInfo->pLinkCtrl;
		if(pEdit)
			pParent = (CBCFuglMeyerBalPage*)pEdit->GetParent();
	}
	else if(pFieldInfo->dwCtrlType == IBT_ComboBox)
	{
		CLinkComboBox* pCombo = (CLinkComboBox*)pFieldInfo->pLinkCtrl;
		if(pCombo)
			pParent = (CBCFuglMeyerBalPage*)pCombo->GetParent();
	}
	else
	{
		ASSERT(FALSE);
	}
	
	if(pParent == NULL)
	{
		ASSERT(FALSE);
		return FALSE;
	}
	
	return PageScoreFieldsCheck(pParam, 0, 2, pParent->m_InputFieldArray3, INPUT_EDIT_CTRL_COUNT);
}

BOOL CBCFuglMeyerBalPage::ShowTableDataWithStartCol(CString strMRN, int nDiagSN, int nStartCol)
{
	INPUT_FIELD_INFO* ppCtrlArray[3];
	ppCtrlArray[0] = m_InputFieldArray1;
	ppCtrlArray[1] = m_InputFieldArray2;
	ppCtrlArray[2] = m_InputFieldArray3;

	CWnd* apDateLabel[3];
	apDateLabel[0] = GetDlgItem(IDC_STATIC_FMLB_DATE_1);
	apDateLabel[1] = GetDlgItem(IDC_STATIC_FMLB_DATE_2);
	apDateLabel[2] = GetDlgItem(IDC_STATIC_FMLB_DATE_3);
	
	CWnd* apDiagSNArray[3];
	apDiagSNArray[0] = GetDlgItem(IDC_STATIC_DIAGSN1);
	apDiagSNArray[1] = GetDlgItem(IDC_STATIC_DIAGSN2);
	apDiagSNArray[2] = GetDlgItem(IDC_STATIC_DIAGSN3);

	return PageShowTableData(strMRN, nDiagSN, BODYCHECKSCALEID, ppCtrlArray, INPUT_EDIT_CTRL_COUNT, apDateLabel, apDiagSNArray, nStartCol);
}

BOOL CBCFuglMeyerBalPage::ShowTableData(CString strMRN, int nDiagSN)
{
	return ShowTableDataWithStartCol(strMRN, nDiagSN, 2);
}

BOOL CBCFuglMeyerBalPage::SetLastColTitile(CString strDate, int nDiagSN)
{
	CWnd* apDateLabel[3] = {0};
	apDateLabel[2] = GetDlgItem(IDC_STATIC_FMLB_DATE_3);
	
	CString astrDate[3];
	astrDate[2] = strDate;
	
	CWnd* apDiagSNArray[3] = {0};
	apDiagSNArray[2] = GetDlgItem(IDC_STATIC_DIAGSN3);
	
	int anDiagSN[3] = {0};
	anDiagSN[2] = nDiagSN;
	
	return PageShowColTitle(apDateLabel, astrDate, apDiagSNArray, anDiagSN, ARRAY_ELE_COUNT(apDateLabel));
}

BOOL CBCFuglMeyerBalPage::EnableInputControls(BOOL bEnable)
{
	INPUT_FIELD_INFO* ppCtrlArray[3];
	ppCtrlArray[0] = m_InputFieldArray1;
	ppCtrlArray[1] = m_InputFieldArray2;
	ppCtrlArray[2] = m_InputFieldArray3;
	
	return PageEnableInputControls(bEnable, ppCtrlArray, INPUT_EDIT_CTRL_COUNT);
}

BOOL CBCFuglMeyerBalPage::IsPageCurDayBlank()
{
	return CScrollPage::PageIsAllInputBlank(m_InputFieldArray3, INPUT_EDIT_CTRL_COUNT);
}
